import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class InternalAnimations extends SearchingandSortingMethods{
	InfoAnalysis info;
	Controller infoControl;
	AnimationControl control;
	Method method;
	InternalAnimations me=this;
	
	public InternalAnimations(Controller inControl, AnimationControl myControl, String methodName)
	{
		super();
		infoControl=inControl;
		control=myControl;
		info=new InfoAnalysis(infoControl);
		int endIndex=methodName.indexOf('(');
		methodName=methodName.substring(0,endIndex);
		try {
			method=InternalAnimations.class.getMethod(methodName);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			method=null;
			e.printStackTrace();
		} 
		while(getInts().length<(100+3))
		{
			add(getWhatToAdd());
		}
	}
	
	public boolean anythingExtra()
	{
		/*try 
		{
			Thread.sleep(1); // do nothing for 1000 miliseconds (1 second)
		} 
		catch(InterruptedException e)
		{
			e.printStackTrace();
		}*/
		control.update();
		return true;
	}
	
	public ActionListener sort()
	{
		return new Sorter();
	}
	
	private class Sorter implements ActionListener
	{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			try {
				method.invoke(me);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
}
